import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/* Router Modules */
import base from "./modules/base";
import group from "./modules/group";
import exam from "./modules/exam";
import article from "./modules/content";
import order from "./modules/order";
import agent from "./modules/agent";
import user from "./modules/user";
import course from "./modules/course"
import packageManage from "@/router/modules/packageManage";
import distribution from "@/router/modules/distribution";

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
    {
        path: "/",
        meta: {
            title: "首页"
        },
        component: Layout,
        redirect: "/index",
        name: "Index",
        hidden: true,
        children: [
            {
                component: () => import("@/views/models/index"),
                path: "index",
                meta: {
                    title: "首页",
                },
                name: "Index"
            },
            {
                path: "/center",
                name: "center",
                meta: {
                    title: "个人中心",
                },
                component: () => import("@/views/profile/index"),
                hidden: true
            }
        ]
    },
    {
        path: "/common",
        meta: {
            title: "公共查看",
            // roles: ["userManage"],
            icon: "el-icon-s-custom"
        },
        component: Layout,
        redirect: "/common/common-user",
        children:[
            {
                path: "common-user",
                meta: {
                    title: "活跃用户",
                    // roles: ["userManage"],
                    icon: "el-icon-s-custom"
                },
                component: () => import("@/views/models/common/user.vue"),
                name: "common-user-list"
            },
        ],
        hidden: false
    },
    base,
    user,
    exam,
    article,
    order,
    agent,
    packageManage,
    course,
    distribution
];

export const constantRoutes = [
    // ...asyncRoutes,
    // {
    //     path: "/test",
    //     name: "test",
    //     meta: {
    //         title: "测试",
    //         noCache: true
    //     },
    //     component: () => import("@/views/test"),
    //     hidden: true
    // },
    // {
    //     path: "/weixin",
    //     name: "weixin",
    //     meta: {
    //         title: "微信二维码",
    //         noCache: true
    //     },
    //     component: () => import("@/views/qrcodeManage.vue"),
    //     hidden: false,
    //     icon: "el-icon-s-platform",

    // },

    {
        path: "/login",
        name: "login",
        meta: {
            title: "登录",
            noCache: true
        },
        component: () => import("@/views/login/index"),
        hidden: true
    },
    {
        path: "/distributeLogin",
        name: "distributeLogin",
        meta: {
            title: "登录",
            noCache: true
        },
        component: () => import("@/views/login/distributionIndex.vue"),
        hidden: true
    },
    {
        path: "/401",
        name: "401",
        meta: {
            title: "无权限"
        },
        component: () => import("@/views/error-page/401"),
        hidden: true
    },
    {
        path: "/403",
        name: "403",
        meta: {
            title: "无法访问"
        },
        component: () => import("@/views/error-page/403"),
        hidden: true
    },
    {
        path: "/check-health",
        meta: {
            title: ""
        },
        component: () => import("@/layout/emptyRouter"),
        hidden: true
    },


    {
        path: "*",
        meta: {
            title: ""
        },
        component: () => import("@/views/error-page/404"),
        hidden: true
    },
    // 404 page must be placed at the end !!!
    // { path: "*", redirect: "/404", hidden: true }

];
const createRouter = () =>
    new Router({
        mode: "history",
        scrollBehavior: () => ({
            y: 0
        }),
        // base: "admin/",
        routes: constantRoutes
    });

const router = createRouter();

export function resetRouter() {
    const newRouter = createRouter();
    router.matcher = newRouter.matcher; // reset router
}

export default router;
